<?php
class daka_classModel extends RelationModel
{
    public $_validate = array(
        array('cat_id', 'require', '课堂分类不可为空'), //不能为空
        array('cname', 'require', '课堂名字不可为空'), //不能为空
        array('content', 'require', '课堂图片不可为空'), //不能为空
    );

    protected $_link = array(
        //关联角色
        'cat' => array(
            'mapping_type' => BELONGS_TO,
            'class_name' => 'daka_class_cat',
            'foreign_key' => 'cat_id',
        ),
    );
	public $cache_name = 'class/list';
	/**
     * 后台有更新则删除缓存
     */
    protected function _before_write($data, $options) {
        F($this->cache_name, NULL);
		F('teacher/list', NULL);
		F('cat/list', NULL);
    }
	protected function _after_delete($data,$options) {
		F($this->cache_name, NULL);
		F('teacher/list', NULL);
		F('cat/list', NULL);
	}
	public function cacheData() {
		if (false === F($this->cache_name)) {
            $map['status'] = 1;
			//判断这个课堂分类是否开启
			$map['cat_id'] = array('in',get_status('daka_class_cat'));
			$list = $this->where($map)->order('ordid asc')->relation(true)->select();
			if(!$list){
				$list = 0;
			}else{
				
			}
			F($this->cache_name,$list);
        }
		return F($this->cache_name);
    }
	
}